import { Controller } from "../../mvc/core/Controller";
import { INormalGuideController } from "./interfaces/INormalGuideController";
import { NormalGuideBaseIcon } from "../view/guild/normalGuide/NormalGuideBaseIcon";
import { ResFileConst } from "../resource/ResFileConst";
import { PetMingGuideWindow } from "../view/guild/normalGuide/PetMingGuideWindow";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { DataEvent } from "../events/DataEvent";
import { SystemSetter } from "../view/system/SystemSetter";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
//class NormalGuideController
    
    export  class NormalGuideController extends Controller implements INormalGuideController
    {
       

        public get petMingIcon(): NormalGuideBaseIcon
        {
            if (this._petMingIcon == null) 
            {
                this._petMingIcon = new NormalGuideBaseIcon(ResFileConst.PetMingBtn);
                this._petMingIcon.addEventListener(flash.events.MouseEvent.CLICK, this.onPetMingIconClickHandler);
            }
            return this._petMingIcon;
        }

        public get petMingGuideWindow(): PetMingGuideWindow
        {
            if (this._petMingGuidWindow == null) 
            {
                this._petMingGuidWindow = new PetMingGuideWindow();
                this._petMingGuidWindow.guideEndFuc = this.guidePetMingEnd;
            }
            return this._petMingGuidWindow;
        }

        /* internal  */onPetMingIconClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.petMingGuideWindow.show();
            return;
        }

        protected /* override */ initServer(): void
        {
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler);
            Dispatcher.addEventListener(EventName.SysSettingSuccess, this.onLoginGameSuccessHandler);
            Dispatcher.addEventListener(EventName.Guide_PetLifeDressOptEnd, this.onPetLifeDressOptEndHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateHunterTaskEnd, this.onHunterTaskEndHandler);
            return;
        }

        /* internal  */onRoleLevelUpdateHandler(arg1: Object): void
        {
            this.guidePetMing();
            return;
        }

        /* internal  */onLoginGameSuccessHandler(arg1: DataEvent): void
        {
            this.guidePetMing();
            return;
        }

        /* internal  */guidePetMing(): void
        {
            var loc1=cache.role.entityInfo.level;
            if (loc1 >= 70 && !SystemSetter.currentSetter.isPetMingGuide && !this._isHunterTaskEnd) 
            {
                this.petMingIcon.show();
            }
            return;
        }

        /* internal  */guidePetMingEnd(): void
        {
            if (this._petMingIcon && !this._petMingIcon.isHide) 
            {
                this._petMingIcon.hide();
                this._petMingIcon.clean();
                this._petMingIcon.removeEventListener(flash.events.MouseEvent.CLICK, this.onPetMingIconClickHandler);
            }
            return;
        }

        /* internal  */onPetLifeDressOptEndHandler(arg1: DataEvent): void
        {
            SystemSetter.localSetter.isPetMingGuide = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow));
            this.guidePetMingEnd();
            return;
        }

        /* internal  */onHunterTaskEndHandler(arg1: MessageBlock): void
        {
            this._isHunterTaskEnd = true;
            this.guidePetMingEnd();
            return;
        }

        private /* var */_petMingIcon: NormalGuideBaseIcon;

        private /* var */_petMingGuidWindow: PetMingGuideWindow;

        private /* var */_isHunterTaskEnd: Boolean=false;
    }
